#include<bits/stdc++.h>
using namespace std;

struct node{
    int d,v,a;
}car[100010];

int t;
int n,m,l,V,num,ans;
int p[100010];
vector<vector<bool>> g;

int main(){

    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);

    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>n>>m>>l>>V;
        for(int i=1;i<=n;i++){
            cin>>car[i].d>>car[i].v>>car[i].a;
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        for(int i=1;i<=n;i++){
            int q,z;
            if(car[i].a==0){
                if(car[i].v>V){
                    q=car[i].d;
                    z=l;
                }
            }
            if(car[i].a>0){
                if(car[i].v>V){
                    q=car[i].d;
                    z=l;
                }
                if(car[i].v==V){
                    q=car[i].d+1;
                    z=l;
                }
                if(car[i].v<V){
                    int len=(V*V-car[i].v*car[i].v)/(car[i].a*2);
                    q=car[i].d+len+1;
                    z=l;
                }
            }
            if(car[i].a<0){
                if(car[i].v>V){
                    q=car[i].d;
                    int len=(V*V-car[i].v*car[i].v)/(car[i].a*2);
                    z=q+len;
                }
            }
            int flag=0;
            for(int j=1;j<=m;j++){
                if(p[j]>=q&&p[j]<=z){
                    g[p[j]][i]=true;
                    flag=1;
                }
            }
            if(flag==1){
                ans++;
            }
        }
        cout<<ans<<' '<<ans<<endl;
    }

    return 0;
}
